﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateWPOnRobotTCPF.CUiCreateWpOnTCPFTCDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.CreateWeldPoint;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Layout;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CreateWPOnRobotTCPF;

internal class CUiCreateWpOnTCPFTCDlg : TxForm
{
  private CApCreateWpOnTCPFTCLogic _logic = new CApCreateWpOnTCPFTCLogic();
  private IContainer components;
  private TextBox ebMfgName;
  private Label lblMfgName;
  private Button btnOK;
  private Button btnCancel;
  public TxObjEditBoxCtrl txebWeldContainer;
  public TxObjEditBoxCtrl txebWeldOperation;
  private Label lblRobotName;
  private Label lblWeldContainer;
  private Label lblWeldOperation;
  private Button btnApply;
  public TxObjEditBoxCtrl txcbRobot;

  public CUiCreateWpOnTCPFTCDlg()
  {
    this.InitializeComponent();
    ((Control) this).MinimumSize = new Size(TxScaling.ScaleByDpi(288), TxScaling.ScaleByDpi(199));
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (TxRobot));
    txTypeFilter.AddIncludedType(typeof (ITxTool));
    this.txcbRobot.SetValidator((ITxValidator) new TxTypeFilterValidator((ITxTypeFilter) txTypeFilter));
  }

  protected void CUiCreateWpOnTCPFTCDlg_Load(object sender, EventArgs e)
  {
    if (this._logic.IsWeldPointPrivate)
      this.CutWeldContainerFromForm();
    this.SetPickProviders();
    this.SetValidators();
    this.LoadPreselectedObjectsIntoControls();
    this.ebMfgName.Text = CApCreateWpTCLogic.GetUniqueWPDisplayName();
    this.FocusEmptyField();
    this.EnableOrDisableAcceptButtons((object) null, (EventArgs) null);
  }

  protected void EnableOrDisableAcceptButtons(object sender, EventArgs e)
  {
    bool flag = this._logic.IsDataValid(this.txcbRobot.Object, this.ebMfgName.Text, this.txebWeldContainer.Object, this.txebWeldOperation.Object);
    this.btnOK.Enabled = flag;
    this.btnApply.Enabled = flag;
  }

  protected void btnOK_Click(object sender, EventArgs e)
  {
    this._logic.Accept(this.txcbRobot.Object, this.ebMfgName.Text, this.txebWeldOperation.Object, this.txebWeldContainer.Object);
    ((Form) this).DialogResult = DialogResult.Yes;
    ((Form) this).Close();
  }

  protected void btnApply_Click(object sender, EventArgs e)
  {
    this._logic.Accept(this.txcbRobot.Object, this.ebMfgName.Text, this.txebWeldOperation.Object, this.txebWeldContainer.Object);
    ((Form) this).DialogResult = DialogResult.Yes;
  }

  protected void btnCancel_Click(object sender, EventArgs e) => ((Form) this).Close();

  protected void LoadPreselectedObjectsIntoControls()
  {
    if (this.txebWeldContainer.Enabled)
    {
      ITxObject selectedWeldContainer = this._logic.GetSelectedWeldContainer();
      if (selectedWeldContainer != null)
        this.txebWeldContainer.Object = selectedWeldContainer;
    }
    ITxObject selectedWeldOperation = this._logic.GetSelectedWeldOperation();
    if (selectedWeldOperation != null)
      this.txebWeldOperation.Object = selectedWeldOperation;
    ITxObject selectedRobot = this._logic.GetSelectedRobot();
    if (selectedRobot != null)
      this.txcbRobot.Object = selectedRobot;
    else
      this.txcbRobot.Object = (ITxObject) this._logic.GetRobotFromOperation(this.txebWeldOperation.Object);
  }

  protected void SetPickProviders()
  {
    TxPickProvider[] pickProviders = CApCreateWpTCLogic.GetPickProviders();
    this.txcbRobot.SetPickProviders(pickProviders);
    this.txcbRobot.ListenToPick = true;
    if (this.txebWeldContainer.Enabled)
    {
      this.txebWeldContainer.SetPickProviders(pickProviders);
      this.txebWeldContainer.ListenToPick = true;
    }
    this.txebWeldOperation.SetPickProviders(pickProviders);
    this.txebWeldOperation.ListenToPick = true;
  }

  protected void SetValidators()
  {
    if (this.txebWeldContainer.Enabled)
      this.txebWeldContainer.SetValidator((ITxValidator) this._logic._CompositeWeldContainerValidator);
    this.txebWeldOperation.SetValidator((ITxValidator) this._logic._CompositeWeldOperationValidator);
  }

  protected void FocusEmptyField()
  {
    if (this.txcbRobot.Object == null)
    {
      this.txcbRobot.Focus();
      this.txcbRobot.Select();
    }
    else if (this.txebWeldContainer.Enabled && this.txebWeldContainer.Object == null)
    {
      this.txebWeldContainer.Focus();
      this.txebWeldContainer.Select();
    }
    else
    {
      if (this.txebWeldOperation.Object != null)
        return;
      this.txebWeldOperation.Focus();
      this.txebWeldOperation.Select();
    }
  }

  protected void CutWeldContainerFromForm()
  {
    int num = ((Control) this.txebWeldContainer).Top - this.ebMfgName.Bottom;
    foreach (Control control in (ArrangedElementCollection) ((Control) this).Controls)
    {
      if (control.Top > ((Control) this.txebWeldContainer).Top)
        control.Top -= ((Control) this.txebWeldContainer).Height + num;
    }
    ((Control) this.txebWeldContainer).Visible = false;
    this.txebWeldContainer.Enabled = false;
    this.lblWeldContainer.Visible = false;
    ((Control) this).Height = ((Control) this).Height - (((Control) this.txebWeldContainer).Height + num);
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiCreateWpOnTCPFTCDlg));
    this.ebMfgName = new TextBox();
    this.lblMfgName = new Label();
    this.btnOK = new Button();
    this.btnCancel = new Button();
    this.txebWeldContainer = new TxObjEditBoxCtrl();
    this.txebWeldOperation = new TxObjEditBoxCtrl();
    this.lblRobotName = new Label();
    this.lblWeldContainer = new Label();
    this.lblWeldOperation = new Label();
    this.btnApply = new Button();
    this.txcbRobot = new TxObjEditBoxCtrl();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.ebMfgName, "ebMfgName");
    this.ebMfgName.Name = "ebMfgName";
    this.ebMfgName.TextChanged += new EventHandler(this.EnableOrDisableAcceptButtons);
    componentResourceManager.ApplyResources((object) this.lblMfgName, "lblMfgName");
    this.lblMfgName.Name = "lblMfgName";
    componentResourceManager.ApplyResources((object) this.btnOK, "btnOK");
    this.btnOK.Name = "btnOK";
    this.btnOK.Click += new EventHandler(this.btnOK_Click);
    this.btnCancel.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this.btnCancel, "btnCancel");
    this.btnCancel.Name = "btnCancel";
    this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
    this.txebWeldContainer.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.txebWeldContainer.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.txebWeldContainer, "txebWeldContainer");
    ((Control) this.txebWeldContainer).Name = "txebWeldContainer";
    this.txebWeldContainer.Object = (ITxObject) null;
    this.txebWeldContainer.PickAndClear = false;
    this.txebWeldContainer.PickLevel = (TxPickLevel) 1;
    this.txebWeldContainer.PickOnly = false;
    this.txebWeldContainer.ReadOnly = false;
    this.txebWeldContainer.ValidatorType = (TxValidatorType) 0;
    this.txebWeldContainer.TypeInvalid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldContainer.TypeValid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldContainer.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldOperation.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.txebWeldOperation.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.txebWeldOperation, "txebWeldOperation");
    ((Control) this.txebWeldOperation).Name = "txebWeldOperation";
    this.txebWeldOperation.Object = (ITxObject) null;
    this.txebWeldOperation.PickAndClear = false;
    this.txebWeldOperation.PickLevel = (TxPickLevel) 1;
    this.txebWeldOperation.PickOnly = false;
    this.txebWeldOperation.ReadOnly = false;
    this.txebWeldOperation.ValidatorType = (TxValidatorType) 0;
    this.txebWeldOperation.TypeInvalid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldOperation.TypeValid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldOperation.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.EnableOrDisableAcceptButtons);
    componentResourceManager.ApplyResources((object) this.lblRobotName, "lblRobotName");
    this.lblRobotName.Name = "lblRobotName";
    componentResourceManager.ApplyResources((object) this.lblWeldContainer, "lblWeldContainer");
    this.lblWeldContainer.Name = "lblWeldContainer";
    componentResourceManager.ApplyResources((object) this.lblWeldOperation, "lblWeldOperation");
    this.lblWeldOperation.Name = "lblWeldOperation";
    componentResourceManager.ApplyResources((object) this.btnApply, "btnApply");
    this.btnApply.Name = "btnApply";
    this.btnApply.Click += new EventHandler(this.btnApply_Click);
    this.txcbRobot.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.txcbRobot.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.txcbRobot, "txcbRobot");
    ((Control) this.txcbRobot).Name = "txcbRobot";
    this.txcbRobot.Object = (ITxObject) null;
    this.txcbRobot.PickAndClear = false;
    this.txcbRobot.PickLevel = (TxPickLevel) 1;
    this.txcbRobot.PickOnly = false;
    this.txcbRobot.ReadOnly = false;
    this.txcbRobot.ValidatorType = (TxValidatorType) 0;
    this.txcbRobot.TypeInvalid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txcbRobot.TypeValid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txcbRobot.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.EnableOrDisableAcceptButtons);
    ((Form) this).AcceptButton = (IButtonControl) this.btnOK;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.btnCancel;
    ((Control) this).Controls.Add((Control) this.txcbRobot);
    ((Control) this).Controls.Add((Control) this.btnApply);
    ((Control) this).Controls.Add((Control) this.lblWeldOperation);
    ((Control) this).Controls.Add((Control) this.lblWeldContainer);
    ((Control) this).Controls.Add((Control) this.lblRobotName);
    ((Control) this).Controls.Add((Control) this.txebWeldOperation);
    ((Control) this).Controls.Add((Control) this.txebWeldContainer);
    ((Control) this).Controls.Add((Control) this.btnOK);
    ((Control) this).Controls.Add((Control) this.btnCancel);
    ((Control) this).Controls.Add((Control) this.ebMfgName);
    ((Control) this).Controls.Add((Control) this.lblMfgName);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiCreateWpOnTCPFTCDlg);
    ((Form) this).Load += new EventHandler(this.CUiCreateWpOnTCPFTCDlg_Load);
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
